<!DOCTYPE html>
<html>
    <head>
        <title>主持学堂</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        
        <link rel="stylesheet" href="Public/JQMobile/jquery.mobile-1.4.5.min.css">
        <link rel="stylesheet" href="Public/JQMobile/themes/kmic.css" />
        <link rel="stylesheet" href="Public/JQMobile/themes/jquery.mobile.icons.min.css" />
        
        <link rel="stylesheet" href="Public/JQMobile/lib/iScroll/jquery.mobile.iscrollview.css" />
        <link rel="stylesheet" href="Public/JQMobile/lib/iScroll/jquery.mobile.iscrollview-pull.css" />
        <!-- 引入 jQuery 库 -->
        <script src="Public/jquery.min.js"></script>

        <!-- 引入 jQuery Mobile 库 -->
        <script src="Public/JQMobile/jquery.mobile-1.4.5.min.js"></script>
        <script src="Public/JQMobile/lib/iScroll/iscroll.js"></script>
        <script src="Public/JQMobile/lib/iScroll/jquery.mobile.iscrollview.js"></script>
        <script src="./Public/timeFormat.js"></script>
        <!--<script src="./Public/wxmenu.js"></script>-->
        
        <!--<link rel="stylesheet" href="Public/noClick.css" />-->
        <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
        <script type="text/javascript">
            wx.config({
                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                appId: 'wxf20953cc201449dd', // 必填，公众号的唯一标识
                timestamp: '{$Think.session.timestamp}', // 必填，生成签名的时间戳
                nonceStr: '{$Think.session.nonceStr}', // 必填，生成签名的随机串
                signature: '{$signature}',// 必填，签名，见附录1
                jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
            });
            
            wx.ready(function(){
                    wx.onMenuShareTimeline({
                        title: '开麦学堂', // 分享标题
                        link: 'http://www.kmic168.com/?m=web&c=school', // 分享链接,将当前登录用户转为puid,以便于发展下线
                        desc: '主持稿、主持技巧等丰富素材，尽在这里',
                        imgUrl: 'http://www.kmic168.com/Public/share2.jpg', // 分享图标
                        success: function () { 
                            // 用户确认分享后执行的回调函数
                        },
                        cancel: function () { 
                            // 用户取消分享后执行的回调函数
                        },
                        trigger: function (res) {
//                            alert("分享到朋友圈按钮点击");        
                        },
                        fail: function (res) {
//                            alert(JSON.stringify(res));
                        }
                    });
                    
                    wx.onMenuShareAppMessage({
                        title: '开麦学堂', // 分享标题
                        desc: '主持稿、主持技巧等丰富素材，尽在这里', // 分享描述
                        link: 'http://www.kmic168.com/?m=web&c=school', // 分享链接
                        imgUrl: 'http://www.kmic168.com/Public/share2.jpg', // 分享图标
                        type: 'link', // 分享类型,music、video或link，不填默认为link
                        dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                        success: function () { 
                            // 用户确认分享后执行的回调函数
                        },
                        cancel: function () { 
                            // 用户取消分享后执行的回调函数
                        }
                    });
                });
        </script>
        <style>
/*            .title{font-size: 18px;}
            .time{color: #cccccc;font-size: 14px;}
            .desc{border-bottom:1px #ff629a solid; }*/
            .ui-content li{background-color: white;}
            /*.ui-content{background-color: white;}*/
            .ui-first-child{ background-color: #FFFFFF;}
            #list li a{background-color: #FFFFFF !important; color: #666 !important}
             #list li p{ color: #999 !important}
             .ui-content{ font-size: 14px !important; text-shadow: none !important;}
              body{font-family:"Microsoft YaHei",微软雅黑; }
        </style>
    </head>
    <body>
        <div data-role="page" id="base">
            <div data-role="panel" id="mypanelc1" data-position="left" data-display="push" data-theme="b">
                <ul data-role="listview">
                    <li><a href="#page" data-rel="close" class="selectChannel1" onclick="sessionStorage.cid1=0">全部</a></li>
                    <foreach name="c1" item="vo">
                        <li><a href="#page" data-rel="close" class="selectChannel1" onclick="sessionStorage.cid1={$vo.id}">{$vo.channel_name}</a></li>
                    </foreach>
                </ul>
            </div><!-- /panel -->
            <div data-role="panel" id="mypanelc2" data-position="left" data-display="push" data-theme="b">
                <ul data-role="listview">
                    <li><a href="#page" data-rel="close" class="selectChannel2" onclick="sessionStorage.cid2=0">全部</a></li>
                    <foreach name="c2" item="vo">
                        <li><a href="#page" data-rel="close" class="selectChannel2" onclick="sessionStorage.cid2={$vo.id}">{$vo.channel_name}</a></li>
                    </foreach>
                </ul>
            </div><!-- /panel -->
            <div data-role="panel" id="mypanelc3" data-position="left" data-display="push" data-theme="b">
                <ul data-role="listview">
                    <li><a href="#page" data-rel="close" class="selectChannel3" onclick="sessionStorage.cid3=0">全部</a></li>
                    <foreach name="c3" item="vo">
                        <li><a href="#page" data-rel="close" class="selectChannel3" onclick="sessionStorage.cid3={$vo.id}">{$vo.channel_name}</a></li>
                    </foreach>
                </ul>
            </div><!-- /panel -->
            <div data-role="header" data-position="fixed" style="position: fixed;">
                <!--<a href="#mypanel" class="ui-btn ui-corner-all ui-icon-bullets">分类</a>-->
                <h1>主持学堂大厅</h1>
                <!--nav-->
            <div data-role="navbar">
                <ul>
                    <li><a href="#mypanelc1" >活动类型</a></li>
                    <li><a href="#mypanelc2">行业</a></li>
                    <li><a href="#mypanelc3">节日</a></li>
                </ul>
            </div>
            </div>
            
            <div role="main" class="ui-content" >
                
                <ul data-role="listview" id="list" style="  background-color: #FFFFFF;">
                    
                    
            
                </ul>
            </div>
            
        </div>
        <!--内容页-->
        <div data-role="page" id="content">
            <div data-role="header" data-position="fixed" style="position: fixed;">
                <a href="#" data-rel="back" class="ui-btn ui-corner-all  ui-icon-carat-l ui-btn-icon-notext"></a>
                <h1>主持学堂</h1>
            </div>
            <div role="main" class="ui-content" style="background-color: white;" >
                <div style="border-bottom:1px gray solid; font-size: 18px; margin-bottom: 5px; padding-bottom: 5px;" class="title"></div>
                <div style="border-bottom:1px gray solid; font-size: 14px; margin-bottom: 5px; padding-bottom: 5px; color: gray;" class="type"></div>
                <div style="font-size: 14px; size: 14px;" class="articelContent" ></div>
            </div>
            
            <div data-role="popup" id="popupDialog" data-dismissible="false" style="max-width:400px;">
                <div role="main" class="ui-content">
                        <h3 class="ui-title">非VIP查看一篇文章需要使用5积分[48小时内可重复查看，不另外扣积分。][<a data-ajax="false" href="?m=center&c=profile&a=help">获取积分</a>]。成为VIP免费查看。</h3>
            <a href="#base" class="ui-btn" >不看了</a>
            <a href="#" class="ui-btn byPoint" >使用积分</a>
            <a href="#" class="ui-btn member" >成为VIP</a>
<!--                    <a href="#" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-b" data-rel="back">不看了</a>
                    <a href="#" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-b" data-rel="back" data-transition="flow">使用积分</a>
                    <a href="#" class="ui-btn ui-corner-all ui-shadow ui-btn-inline ui-btn-b" data-rel="back" data-transition="flow">成为VIP</a>-->
                </div>
            </div>
        </div>
        
        <script src="Public/ScrollPage.js"></script>
        <script>
            //http://www.kmic168.com/
            var level = {$level};
            $('.selectChannel1').click(function(){
                channelc1 = sessionStorage.cid1;
                $("#list").html('');
                page = 0;
                isEnd = false;
                addMore();
                ga('send', 'event', 'school', 'checkchannel', sessionStorage.cid1);
            });
            $('.selectChannel2').click(function(){
                channelc2 = sessionStorage.cid2;
                $("#list").html('');
                page = 0;
                isEnd = false;
                addMore();
                ga('send', 'event', 'school', 'checkchannel', sessionStorage.cid2);
            });
            $('.selectChannel3').click(function(){
                channelc3 = sessionStorage.cid3;
                $("#list").html('');
                page = 0;
                isEnd = false;
                addMore();
                ga('send', 'event', 'school', 'checkchannel', sessionStorage.cid3);
            });
            /////
            $('.member').click(function(){
                window.location.href="?m=Center&c=Profile&a=member";
            });
            
            $('.byPoint').click(function(){
                $.ajax({
                    type: 'POST',
                    url: "?m=web&c=school&a=getArticleDetails",
                    data: {'id':sessionStorage.aid,'byPoint':1},
                    success: function(result){
                        console.log(result);
                        if (result.code == 1) {
                            alert('积分不够');
                            $.mobile.changePage ('#base');
                            exit();
                        }
                        $('.articelContent').html(result.data.content);
                        $('.title').html(result.data.title);
                        var c1name = result.data.c1name==null?'':" | "+result.data.c1name+" | ";
                        var c2name = result.data.c2name==null?'':" | "+result.data.c2name+" | ";
                        var c3name = result.data.c3name==null?'':" | "+result.data.c3name+" | ";
                        $('.type').html("发布时间:"+formatTime(result.data.timeline)+c1name+c2name+c3name+result.data.value+"");
                        //
                        $.mobile.loading("hide");
                        $( "#popupDialog" ).popup( "close" );
                    },
                    beforeSend: function(){
                        $.mobile.loading("show", {
                            text: "加载中..",
                            textVisible: true
                        });
                    },
                    dataType: 'json'
                }); 
                ga('send', 'event', 'school', 'checkGetArticleDetails', sessionStorage.aid);
            });
            
            function formatTime(timestamp){
                var d = new Date(timestamp * 1000);    //根据时间戳生成的时间对象
                var date = (d.getFullYear()) + "-" + 
                           (d.getMonth() + 1) + "-" +
                           (d.getDate()) ;
                   return date;
            }
            $('#content').on('pageshow',null, function(event, ui){
//                alert(level);
                ga('send', 'event', 'school', 'check', '{$Think.session.id}');
                $.ajax({
                    type: 'POST',
                    url: "?m=web&c=school&a=getArticleDetails",
                    data: {'id':sessionStorage.aid,'openid':'{$Think.session.openid}'},
                    success: function(result){
//                            console.log(result);
                        $('.articelContent').html(result.data.content);
                        $('.title').html(result.data.title);
                        var c1name = result.data.c1name==null?'':" | "+result.data.c1name;
                        var c2name = result.data.c2name==null?'':" | "+result.data.c2name;
                        var c3name = result.data.c3name==null?'':" | "+result.data.c3name;
                        $('.type').html("发布时间:"+formatTime(result.data.timeline)+c1name+c2name+c3name+' | '+result.data.value+"");
                        //
                        $.mobile.loading("hide");
                    },
                    beforeSend: function(){
                        $.mobile.loading("show", {
                            text: "加载中..",
                            textVisible: true
                        });
                    },
                    dataType: 'json'
                }); 
                ga('send', 'event', 'school', 'checkGetArticleDetails', sessionStorage.aid);
                ga('send', 'event', 'school', 'checkIsmember', '{$Think.session.id}');
                
            });
            
            var isFirstLoadBase = true;
            $('#base').on('pageshow',null, function(event, ui){
                if (isFirstLoadBase == true) {
                    isFirstLoadBase = false;
                    $.mobile.loading("show", {
                        text: "加载中..",
                        textVisible: true
                    });
                }
            });
            
            var channelc1 = 0;
            var channelc2 = 0;
            var channelc3 = 0;
            /* add more function */
            function addMore() {
                $.ajax({
                    type: 'POST',
                    url: "?m=web&c=school&a=getArticles",
                    data: {'page':page,'channelc1':channelc1,'channelc2':channelc2,'channelc3':channelc3},
                    success: function(result){
                        console.log(result);
                        $.mobile.loading("hide");
                        //
                        $("#list li").last().remove();
                        //
                        var items = '';
                        result.forEach(function(e){  
                            var c1name = e.c1name==null?'':" | "+e.c1name+"";
                            var c2name = e.c2name==null?'':" | "+e.c2name+"";
                            var c3name = e.c3name==null?'':" | "+e.c3name+"";
                           items += "<li>\
        <a href=\"#content\" onclick=\"sessionStorage.aid="+e.id+"; \">\
        <h2>" + e.title + "</h2>\
        <p style=\"white-space:pre-wrap;\">"+e.description+"</p>\
        <p style=\"white-space:pre-wrap;\">发布时间:"+formatTime(e.timeline)+c1name+c2name+c3name+" | "+e.value+"</p>\
        </a>\
      </li>"; 
                        });
                        $("#list").append(items).listview("refresh");
                        //
                        if (result.length > 0) {
                            page++;
                            var loadingHTML = '<li>加载中...</li>'
                            $("#list").append(loadingHTML).listview("refresh");
                        }else{
                            var loadingHTML = '<li>没有更多...</li>'
                            $("#list").append(loadingHTML).listview("refresh");
                            isEnd = true;
                        }
                        
                    },
                    beforeSend: function(){
                        $.mobile.loading("show", {
                            text: "加载中..",
                            textVisible: true
                        });
                    },
                    dataType: 'json'
                }); 
            }

            /* attach if scrollstop for first time */
            $(document).on("scrollstop", checkScroll);
            var openid = '{$Think.session.openid}';
        </script>
                 <script src="./Public/UnionInfo.js"></script>
         <script src="./Public/public_js.js"></script>
        <script src="./Public/ga.js"></script>
    </body>
</html>
